// /*
//  * @Description:
//  * @Version: 1.0
//  * @Autor: wangmeng
//  * @Date: 2021-08-02 14:37:54
//  * @LastEditors: wamgmeng
//  * @LastEditTime: 2024-01-19 20:16:00
//  */
// /* eslint-disable import/no-extraneous-dependencies */
// /* eslint-disable no-param-reassign */
// // gzip压缩插件

const CompressionWebpackPlugin = require("compression-webpack-plugin");
const { DefinePlugin } = require("webpack");

module.exports = {
  publicPath: "./",
  assetsDir: "static",
  outputDir: undefined,
  runtimeCompiler: undefined,
  parallel: undefined,
  // 不在production环境使用SourceMap
  productionSourceMap: false,
  pages: {
    index: {
      entry: "src/main.ts",
      title: "博汇科技超高清体验评测系统",
    },
  },

  devServer: {
    port: 3008,
    proxy: {
      "/api": {
        target: "http://172.17.122.17:8070",
        ws: true,
        changeOrigin: true,
        logLevel: "debug",
      },
      "/systemDefaultData": {
        target: "http://172.17.122.17:8070",
        ws: true,
        changeOrigin: true,
        logLevel: "debug",
      },
      "/systemConfigData": {
        target: "http://172.17.122.17:8070",
        ws: true,
        changeOrigin: true,
        logLevel: "debug",
      },
    },
    open: true,
    compress: true,
    disableHostCheck: true, // webpack4.0 开启热更新
  },
  configureWebpack: (config) => {
    // 将插件添加到现有的插件数组中
    config.plugins.push(
      new DefinePlugin({
        __VUE_OPTIONS_API__: JSON.stringify(true),
        __VUE_PROD_DEVTOOLS__: JSON.stringify(false),
        __VUE_PROD_HYDRATION_MISMATCH_DETAILS__: JSON.stringify(false),
      })
    );

    let plugins = [];
    if (process.env.NODE_ENV === "production") {
      // 为生产环境修改配置...
      // 移除console.log
      config.optimization.minimizer[0].options.terserOptions.compress.warnings = false;
      config.optimization.minimizer[0].options.terserOptions.compress.drop_console = true;
      config.optimization.minimizer[0].options.terserOptions.compress.drop_debugger = true;
      config.optimization.minimizer[0].options.terserOptions.compress.pure_funcs =
        ["console.log"];

      plugins = [
        new CompressionWebpackPlugin({
          test: new RegExp(`\\.(${["js", "css"].join("|")})$`),
          threshold: 10240,
          minRatio: 0.8,
        }),
      ];
      config.plugins = [...config.plugins, ...plugins];
    }
  },
  css: {
    loaderOptions: {
      sass: {
        // 具体路径根据你们项目来
        prependData: `@use "@/assets/css/variable.scss" as *;`,
      },
      scss: {
        prependData: `@use "@/assets/css/variable.scss" as *;`,
      },
    },
  },
};
